package com.sun.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sun.mapper.NameMapper;
import com.sun.pojo.BogusColleges;
import com.sun.pojo.SchoolName;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Connection;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Controller
public class NameContorller {
    @Autowired
    private NameMapper nameMapper;

    @RequestMapping("/schoolName/{pageNo}")
    public Object page(@PathVariable("pageNo") Integer pageNo, Model model) {
        PageHelper.startPage(pageNo, 10);
        List<SchoolName> list = nameMapper.selectAllDate();
        PageInfo<SchoolName> page = new PageInfo<>(list, 5);
        model.addAttribute("list", page);
        System.out.println(page);
//        return page;
        return "SchoolName/list";
    }

    @RequestMapping("/name")
    public String po(@RequestParam(value = "pageNo1",defaultValue = "0") Integer pageNo1,
                     Model model){
        PageHelper.startPage(pageNo1, 10);
        List<SchoolName> list = nameMapper.selectAllDate();
        PageInfo<SchoolName> page = new PageInfo<>(list, 5);
        model.addAttribute("list", page);
        return "SchoolName/list";
    }
    @RequestMapping("/name1/{name}")
    @ResponseBody
    public Object date(@PathVariable("name")String name,Model model){
        List<Map> list=  nameMapper.selectDate(name);
        System.out.println(list);
        return list ;
    }
    @RequestMapping("/name/{name}")
    public Object echarts(@PathVariable("name")String name,
                          Model model){
        System.out.println(name);
        model.addAttribute("name", name);
        return "SchoolName/Echarts";
    }

    /*
     *搜索
     * */
    @RequestMapping("/select")
    public String select(@RequestParam("name") String name,
                         Model model){
        System.out.println(name);
//        PageHelper.startPage(1,10);
        List<SchoolName> list = nameMapper.selectNameDate(name);
        System.out.println(list);
        PageInfo<SchoolName> page1 = new PageInfo<>(list, 5);
        model.addAttribute("list", page1);
//        System.out.println(page1);
        return "SchoolName/list";
    }

    @RequestMapping("/type")
    @ResponseBody
    public Object type(){
        Collection<Map<String, Integer>> list=  nameMapper.selectType();
        System.out.println(list);
        return list ;
    }

    @RequestMapping("/985")
    @ResponseBody
    public Object f985(){
        Collection<Map<String, Integer>> list=  nameMapper.select985();
        System.out.println(list);
        return list ;
    }
    @RequestMapping("/211")
    @ResponseBody
    public Object f211(){
        Collection<Map<String, Integer>> list=  nameMapper.select211();
        System.out.println(list);
        return list ;
    }


    @RequestMapping("/selectCount985")
    @ResponseBody
    public Object C985(){
        Collection<Map<String, Integer>> list=  nameMapper.selectCount985();
        System.out.println(list);
        return list ;
    }
    @RequestMapping("/selectCount211")
    @ResponseBody
    public Object C211(){
        Collection<Map<String, Integer>> list=  nameMapper.selectCount211();
        System.out.println(list);
        return list ;
    }


    @RequestMapping("/typeB")
    @ResponseBody
    public Object typeB(){
        Collection<Map<String, Integer>> list=  nameMapper.selectTypeB();
        System.out.println(list);
        return list ;
    }


    @RequestMapping("/name/selectTypeTop5")
    @ResponseBody
    public Object selectTypeTop5(){
        Collection<Map<String, Integer>> list=  nameMapper.selectTypeTop5();
        System.out.println(list);
        return list ;
    }
}
